﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Gao.Poker.Domain;
using Gao.Poker.Services;

namespace Gao.Poker.Command
{
    public class LoginCommand : ICommand
    {
        private Action<Boolean> _action;
        public LoginCommand(Action<Boolean> action)
        {
            _action = action;
        }

        public void Execute(object parameter)
        {
            var vm = parameter as User;
            var service = new UserService();
            if(vm != null && service.Login(vm.UserName,vm.Password) != null)
            {
                _action(true);
            }
            else
            {
                _action(false);
            }
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;
    }
}
